import { _decorator, Component, EventTouch, Input, instantiate, Node, Vec2 } from 'cc';
import { CubeBgLoad } from './CubeBgLoad';
import { GAME_MODE, GAMEDATA } from './GAMEDATA';
import { AssetList, Global } from '../Global';
import { ModelLoad } from './ModelLoad';
import { UIMgr } from '../Mgr/UIMgr';
import { GameEnd } from '../Pop/GameEnd';
import { AudioMgr, SoundName } from '../Mgr/AudioMgr';
import { ControlCubeLoad } from './ControlCubeLoad';
import { ResMgr } from '../Mgr/ResMgr';
import { GameSet } from '../Pop/GameSet';
import { AdMgr } from '../Mgr/AdMgr';
const { ccclass, property } = _decorator;

@ccclass('GameScene')
/**
 * 游戏场景
 */
export class GameScene extends Component {

    //
    static Instance: GameScene = null;

    //砖块背景层
    @property(Node)
    public CubeBgLoad: Node = null;

    //模型层
    @property(Node)
    public ModelLoad: Node = null;

    //操纵方块层
    @property(Node)
    public ControlCubeLoad: Node = null;

    //加分层
    @property(Node)
    public AddScoreLoad: Node = null;

    protected onLoad(): void {
        GameScene.Instance = this;
        Global.IsEnd = false;
    }

    protected start(): void {
        this.CubeBgLoad.getComponent(CubeBgLoad).InitBg();
        this.ModelLoad.getComponent(ModelLoad).UpdateModel();
    }

    /**
     * 游戏结束
     */
    public GameOver() {
        if (Global.IsEnd) return;
        Global.IsEnd = true;
        let gamen_end: Node = UIMgr.Instance.ShowPop(AssetList.Pop.GAMEEND);
        gamen_end.getComponent(GameEnd).UpdateScore(this.ModelLoad.getComponent(ModelLoad).ScoreNum);
    }

    /**
     * 点击刷新按钮
     */
    private UpdateClick() {
        AudioMgr.instance.PlayEffect(SoundName.Click);

        UIMgr.Instance.ShowTop(AssetList.Top.NoTouch);
        AdMgr.Instance.ShowVideo(0, (_isend: boolean) => {
            UIMgr.Instance.HideTop(AssetList.Top.NoTouch);
            if (_isend) this.ControlCubeLoad.getComponent(ControlCubeLoad).AllUpdate(true);
        })


    }

    /**
     * 点击设置按钮
     */
    private SetClick() {
        AudioMgr.instance.PlayEffect(SoundName.Click);
        Global.IsEnd = true;
        let gs: Node = UIMgr.Instance.ShowPop(AssetList.Pop.GAMESET);
        gs.getComponent(GameSet).Init();
    }

}


